package com.enlorenz.core.channel.socket.common.reader;

import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

import com.enlorenz.common.util.MessageBuffer;
import com.enlorenz.core.channel.socket.common.util.NioUtil;

/**
 * Nio默认读取者
 * @author MAC
 */
public class DefaultNioReader implements INioReader{
	private SocketChannel channel;
	private ByteBuffer commBuffer;
	
	public void setChannel(SocketChannel channel) {
		this.channel = channel;
	}

	public void setCommBuffer(ByteBuffer commBuffer) {
		this.commBuffer = commBuffer;
	}

	@Override
	public byte[] read()
			throws Exception {
		MessageBuffer messageBuffer=new MessageBuffer();
		byte [] msg=NioUtil.read(channel, commBuffer,2048);
		messageBuffer.append(msg);
		return messageBuffer.toByte();
	}
	
	
	
}
